package com.ms.education.course.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ms.education.course.entity.Course;
import com.ms.education.course.entity.PushCourse;
import com.ms.education.course.entity.vo.CourseResultVo;
import com.ms.education.course.entity.vo.PageCourseVo;
import com.ms.education.course.mapper.PushCourseMapper;
import com.ms.education.course.service.CourseService;
import com.ms.education.course.service.PushClassService;
import com.ms.education.course.service.PushCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author ms
 * @since 2023-03-06
 */
@Service
public class PushCourseServiceImp extends ServiceImpl<PushCourseMapper, PushCourse> implements PushCourseService {

    @Autowired
    private CourseService courseService;

    @Autowired
    private PushCourseService pushCourseService;

    @Override
    public void deleteCoursePush(Integer courseId, Integer pushId) {
        UpdateWrapper<PushCourse> wrapper = new UpdateWrapper<PushCourse>().eq("course_id", courseId).eq("push_id", pushId);
        remove(wrapper);
    }

    @Override
    public Map<String, Object> getCourseNotInPush(long current, long limit, Integer pushId, PageCourseVo pageCourseVo) {
        QueryWrapper<PushCourse> wrapper = new QueryWrapper<PushCourse>().eq("push_id", pushId).select("course_id");
        List<Integer> courseIds = pushCourseService.list(wrapper).stream().map(PushCourse::getCourseId).collect(Collectors.toList());
        pageCourseVo.setExcludes(courseIds);
        return courseService.pageCourse(pageCourseVo, current, limit);
    }
}
